package dev.alm.ggzxservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dev.alm.ggzxservice.entity.User;
import dev.alm.ggzxservice.mapper.UserMapper;
import dev.alm.ggzxservice.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public User addUser(User user) {
        Date date = new Date();
        user.setCreateTime(date);
        user.setUpdateTime(date);
        int insert = userMapper.insert(user);
        if (insert == 0) {
            return null;
        }
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", user.getUsername());
        return userMapper.selectOne(wrapper);
    }

    @Override
    public User userLogin(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", user.getUsername());
        wrapper.eq("password", user.getPassword());
        return userMapper.selectOne(wrapper);
    }

}
